/**
 *  Copyright 2002-2009 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package foo.bar.wiki.security;

import org.apache.shiro.authz.Permission;
import org.apache.shiro.authz.permission.AllPermission;

import java.util.HashSet;
import java.util.Set;

/**
 * An enum indicating the possible roles that a {@link foo.bar.wiki.domain.User} could have.
 *
 *  user:signup:*
 *  user:ownProfile:*
 *  user:view:*
 *  user:edit:*
 *  user:remove:*
 *
 *  space:addSpace:
 *  space:viewSpace:
 *  space:editSpace:
 *  space:removeSpace:
 *  space:membership:
 *  space:viewSpaceAsWiki:
 *  space:addPage:
 *  space:editPage:
 *  space:viewPage:
 *  space:removePage:
 *  space:viewPageAsWiki
 *  space:commentPage:
 *
 *
 * @author tmjee
 * @version $Date: 2009-03-16 21:46:02 +0800 (Mon, 16 Mar 2009) $ $Id$
 */
public enum RoleType {
    ANONYMOUS() {
        public Set<Permission> permission() {
            /**
             *      user:signup:*
             *      space:viewSpaceAsWiki:*
             *      space:viewPageAsWiki:*
             *      space:commentPage:*
             */
            return new HashSet<Permission>() { {
                add(new ExtendedWildcardPermission2("user:signup:*", true));
                add(new ExtendedWildcardPermission2("space:viewSpaceAsWiki:*", true));
                add(new ExtendedWildcardPermission2("space:viewPageAsWiki:*", true));
                add(new ExtendedWildcardPermission2("space:commentPage:*", true));
            }};
    }},
    REGISTERED_USER() {
        public Set<Permission> permission() {
            return new HashSet<Permission>() { {
                /**
                 *      user:ownProfile:OWN_USER_ID
                 *      space:addSpace:*
                 *      space:viewSpace:OWNER_SPACE_ID
                 *      space:editSpace:OWNER_SPACE_ID
                 *      space:removeSpace:OWNER_SPACE_ID
                 *      space:viewSpaceAsWiki:*
                 *      space:addPage:*
                 *      space:editPage:OWNER_SPACE_ID
                 *      space:viewPage:OWNER_SPACE_ID
                 *      space:removePage:OWNER_SPACE_ID
                 *      space:viewPageAsWiki:*
                 *      space:commentPage:*
                 *      space:membership:OWNER_SPACE_ID
                 */
                add(new ExtendedWildcardPermission2("user:ownProfile:OWN_USER_ID", true));
                add(new ExtendedWildcardPermission2("space:addSpace:*", true));
                add(new ExtendedWildcardPermission2("space:viewSpace:OWNER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:editSpace:OWNER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:removeSpace:OWNER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:viewSpaceAsWiki:*", true));
                add(new ExtendedWildcardPermission2("space:addPage:*", true));
                add(new ExtendedWildcardPermission2("space:editPage:OWNER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:viewPage:OWNER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:removePage:OWNER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:viewPageAsWiki:*", true));
                add(new ExtendedWildcardPermission2("space:commentPage:*", true));
                add(new ExtendedWildcardPermission2("space:membership:OWNER_SPACE_ID", true));
            }};
    }},
    MODERATOR() {
        public Set<Permission> permission() {
            return new HashSet<Permission>() { {
                /**
                 *      user:ownProfile:OWN_USER_ID
                 *      space:addSpace:*
                 *      space:viewSpace:MEMBER_SPACE_ID
                 *      space:editSpace:MEMBER_SPACE_ID
                 *      space:removeSpace:MEMBER_SPACE_ID
                 *      space:viewSpaceAsWiki:*
                 *      space:addPage:*
                 *      space:editPage:MEMBER_SPACE_ID
                 *      space:viewPage:MEMBER_SPACE_ID
                 *      space:removePage:MEMBER_SPACE_ID
                 *      space:viewPageAsWiki:*
                 *      space:commentPage:*
                 *      space:membership:MEMBER_SPACE_ID
                 */
                add(new ExtendedWildcardPermission2("user:ownProfile:OWN_USER_ID", true));
                add(new ExtendedWildcardPermission2("space:addSpace:*", true));
                add(new ExtendedWildcardPermission2("space:viewSpace:MEMBER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:editSpace:MEMBER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:removeSpace:MEMBER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:viewAsWiki:*", true));
                add(new ExtendedWildcardPermission2("space:addPage:*", true));
                add(new ExtendedWildcardPermission2("space:editPage:MEMBER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:viewPage:MEMBER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:removePage:MEMBER_SPACE_ID", true));
                add(new ExtendedWildcardPermission2("space:viewPageAsWiki:*", true));
                add(new ExtendedWildcardPermission2("space:commentPage:*", true));
                add(new ExtendedWildcardPermission2("space:membership:MEMBER_SPACE_ID", true));
            }};
    }},
    ADMINISTRATOR() {
        public Set<Permission> permission() {
            return new HashSet<Permission>() { {
                add(new AllPermission());
            }};
    }};

    public abstract Set<Permission> permission();
    
}
